package com.atguigu.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class DeleteTable {
    /*public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.加载类驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.连接数据库
        String url = "jdbc:mysql://localhost:3306/day04_test01_bookstore";
        Connection conn = DriverManager.getConnection(url, "root", "123456");

        //3.操作数据库
        String sql = "delete  from orders where id = '15275760194821'";
        PreparedStatement pst = conn.prepareStatement(sql);

        int len = pst.executeUpdate();
        System.out.println(len >= 0?"删除成功":"删除失败");
        pst.close();
        conn.close();
    }*/
    public static void main(String[] args)throws Exception {
        //1、注册驱动
        Class.forName("com.mysql.jdbc.Driver");

        //2、获取连接
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/day04_test01_bookstore", "root", "123456");

        //3、编写sql
        String sql = "DELETE FROM orders WHERE id = '15275760194821'";

        //4、创建PreparedStatement
        PreparedStatement pst = conn.prepareStatement(sql);//此时的sql带?的

        //5、执行sql
        int len = pst.executeUpdate();
        System.out.println(len>=0 ? "删除成功" : "删除失败");
        //6、关闭
        pst.close();
        conn.close();
    }
}
